<?php
/**
 * Created by PhpStorm.
 * User: shnaider
 * Date: 22.01.2015
 * Time: 19:50
 */
class admin_models_index extends basecontroller
{

    public static function _login()
    {
        @session_start();
        $secure = new security;

        $key_num1 = $secure->key_num1;
        $key_num2 = $secure->key_num2;

        if (isset($_GET['action'])) {
            $action = $secure->input_cut_filter($_GET['action']);
            $login = $secure->input_cut_filter($_POST['login']);
            $login = DB::escape($login);
            $passw = $secure->input_cut_filter($_POST['passw']);
            $passw = DB::escape($passw);
            $passw = hasher::hash($passw, $key_num1, $key_num2);

            switch ($action) {
                case "login":
                    $data = DB::query_arr('SELECT * FROM users WHERE login="' . $login . '" AND passw="' . $passw . '"');
                    if (!empty($data['0']['login'])) {
                        $_SESSION['logged'] = 'landing-admin';
                        $_SESSION['whois'] = $data['0']['id'];
                        header('location: order?mn=mn1');
                    } else {
                        session_destroy();
                    }

                    unset($data);
                    unset($secure);
                    break;

                case "logout":
                    session_destroy();
                    unset($secure);
                    break;
            }

        }
        unset($secure);

    }

    public static function _is_logged(){
        @session_start();

        if ($_SESSION['logged'] == 'landing-admin'){
            return true;
        }
        else{
            return false;
        }
    }

}